/************** init.html **************/
function query_invOrderInfo(page) {
	sys_loading();
	var parm = $('#queryInvOrderInfoForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('invOrderInfo-query');
	sys_record_parm('invOrderInfo',parm);
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#ResultList').html(result);
		}
	});
}
function shield_invOrderInfo(code) {
	$.Zebra_Dialog('确定要屏蔽吗？',{
	'type': 'question',
	'title': '警告' ,
	'buttons':[
       {caption:'屏蔽',callback:function() {
    	   var url = create_url('invOrderInfo-shield');
    	   aidExecute_invOrderInfo(code, url);
		}},
       {caption:'取消',callback:function(){}
       }]
	});
}

function unshield_invOrderInfo(code, name) {
	$.Zebra_Dialog('确定要解除屏蔽吗？',{
	'type': 'question',
	'title': '警告' ,
	'buttons':[
       {caption:'解除',callback:function() {
    	   var url = create_url('invOrderInfo-unshield');
    	   aidExecute_invOrderInfo(code, url);
		}},
       {caption:'取消',callback:function(){}
       }]
	});
}
function aidExecute_invOrderInfo(code, url) {
	var parm = {'code':code};
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if ('success' == result) {
				query_invOrderInfo();
			} else {
				sys_msg('操作失败，请刷新页面再次尝试，如果问题依然存在，请联系管理员!');
			}
		}
	});
}
//查询类型
function aidQueryBn_invOrderInfo(page) {
	sys_loading();
	var parm = $('#aidQueryForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('invOrderInfo-aidList1');
	$.ajax({type:'POST', url:url, data:parm,success: function(result) {
			sys_loading_close();
			$('#aidResultList').html(result);
			}
		});
	}
function selectBn_invOrderInfo() {
	var url = create_url('invOrderInfo-aidInit1');
	var parm = {'id':'bc', 'name':'bn'};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'900px', height:'700px', open:true, 
			onClosed:function(){
			}
		});
	}

//选择
function chooseBn_invOrderInfo(code, name) {
	$('#bc').val(code);
	$('#bn').val(name);
	$.fn.colorbox.close();
}
//查询商品
function aidQueryCn_invOrderInfo(page) {
	sys_loading();
	var parm = $('#aidQueryCnForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('invOrderInfo-aidList');
	$.ajax({type:'POST', url:url, data:parm,success: function(result) {
			sys_loading_close();
			$('#aidResultList').html(result);
			}
		});
	}
function selectCn_invOrderInfo(btn) {
	var i = btn.attr('pib');
	var parm = {'index':i};
	var url = create_url('invOrderInfo-aidInit');
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'900px', height:'700px', open:true, 
			onClosed:function(){
			}
		});
	}

//选择
function chooseCn_invOrderInfo(code, name) {
	 var p = $('#aid_g_p').val();
	$('#cc_' + p).val(code);
	$('#cname_' + p).val(name);
	$.fn.colorbox.close();
}

//删除多余的空白行
function delete_invOrderInfo(btn) {
  btn.parents('.rep').remove();
}
//添加空白行
function add_invOrderInfo() {
	var tr = $('#tempTable').find('tr').clone(true);
	var i = $('#index').val();
	tr.find('.cname').attr({'id':'cname_' + i, 'name':'itemList[' + i + '].cname'}).end()
		.find('.btn-primary').attr('pib', i).end()
		.find('.cc').attr({'id': 'cc_' + i, 'name': 'itemList[' + i + '].cc'}).end()
		.find('.count').attr('name', 'itemList[' + i + '].count').end()
		.find('.price').attr('name', 'itemList[' + i + '].price').end();
	$('#ListBody').append(tr);
	$('#index').val(parseInt(i) + 1);
}


//检查数量输入只能是数字
function checkNum_invOrderInfo(obj) {
	var v = obj.val();
	if (/^[1-9][0-9]*$/.test(v)) {
	} else {
		sys_msg('只能填数字,而且不能以0开头哦！');
		obj.val('');
	}
	obj.css('border-color','');
}

function save_invOrderInfo() {
	var parm = $('#editForm').serialize();
	var url = create_url('invOrderInfo-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,dataType : 'json',
		success: function(result) {
			sys_submiting_close();
			if (result.result == 'success') {
				sys_msg('操作成功!');
				sys_load_handle('invOrderInfo');
			} else if (result == 'error'){
				sys_msg('操作失败!');
			}
		}
	});
}
//保存并入库
function saveIn_invOrderInfo() {
	//验证输入框是否有未填写的
	var ok = false;
	$('#editForm').find('input').each(function(e) {
		if ('' == this.value || undefined == this.value) {
			$(this).css('border-color','red');
			ok = false;
		} else {
			ok = true;
		}
	});
	if (!ok) {
		sys_msg('不能有空值！');
		return false;
	}
	var parm = $('#editForm').serialize();
	var url = create_url('invOrderInfo-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,dataType:'json',
		success: function(result) {
			sys_submiting_close();
			if (result.result == 'success') {
				sys_load_handle('invOrderInfo-in_' + result.code);
			} else if (result.result == 'error'){
				sys_msg('操作失败!');
			}
		}
	});
}